class Request{
    get (url, data,header) {
      return this.request('GET', url, data,header)
    }
    post (url, data,header) {
      return this.request('POST', url, data,header)
    }
    put (url, data,header) {
      return this.request('PUT', url, data,header)
    }
    request (method, url, data,header) {
      const that = this
      return new Promise((resolve, reject) => {
        wx.request({
          url:url,
          data,
          method,
          header,
          success (res) {
            if (res.statusCode === 200) {
              resolve(res.data)
            } else {
              reject(res)
            }
          },
          fail (res) {
            reject({
              message: res.errMsg,
              url:that.baseURL + url,
              method,
              data,
              statusCode:res.statusCode,
              result:res.data
            })
          }
        })
      })
    }
  }
  
  var  request = new Request({
  })
  
  module.exports = request
  